<!DOCTYPE html>
<html>

	<head lang="en">
		<title>找攻略</title>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
		<script src="/js/jquery/jquery.min.js"></script>
		<script src="/js/bootstrap/js/bootstrap.min.js"></script>
		<link rel="stylesheet" href="/css/font/css/font-awesome.min.css" />
		<link rel="stylesheet" href="/css/reset.css" />
		<link rel="stylesheet" href="/css/strategy.css" />
		<link rel="stylesheet" href="/js/plugins/dialog2/dialog.css" />
		<script src="/js/plugins/jrender/jrender.min.js"></script>
		<script src="/js/plugins/dialog2/dialog.min.js"></script>
		<script src="/js/plugins/jquery-form/jquery.form.js"></script>
        <link rel="stylesheet" href="/css/modalbox.css">


		<script>

            var user = JSON.parse(sessionStorage.getItem('user'));

			$(function () {

                $('.userId').val(user.id);
				//组列表
				$.get('/friends/groups/' + user.id,function (data) {
					$('#group').renderValues({list:data},{
                        set_id:function (item, value) {
							$(item).attr('data-id',value);
                        }
					});
                    pageMaker();
                })

				//好友列表


            });

            function pageMaker(){
                var oUl = $('#list');
                var ah3 = oUl.find('h3');

                ah3.click(function () {
                    var item_h3 = $(this);
                    if($(this).next('ul').find('li')){
                        var groupId = $(this).data('id');
                        var html = "";
                        $.ajax({
                            type: "GET",
                            url: "/friends/groups/friends",
                            data: "groupId=" + groupId,
                            async: false,
                            success: function(data){
                                console.log(data);
                                $.each(data,function (index, item) {
									html = '<li>\n' +
                                        '\t\t\t\t\t\t\t\t\t\t<a href="/friend/interface/person/friendProfiles.html?id='+ item.friend.id +'&groupId='+ item.group.id +'">\n' +
                                        '\t\t\t\t\t\t\t\t\t\t<img  width="40px" class="rounded-circle head-img" src="'+ item.friend.headImgUrl +'">\n' +
                                        '\t\t\t\t\t\t\t\t\t\t<span >'+ item.friend.nickName +'</span> </a>\n' +
                                        '\t\t\t\t\t\t\t\t\t</li>'
                                });
                                item_h3.next('ul').html(html);
                            }
						})
                    }
                    console.log(1);
                    if($(this).hasClass('active')){
                        $(this).toggleClass("active");
                        $(this).next('ul').css('display','none');
                    }else{
                        ah3.removeClass();
                        $('#list ul').css('display','none');
                        $(this).addClass('active');
                        $(this).next('ul').css('display','block');
                    };
                });


                $('#list ul').on('click','li',function(){
                    $('#list ul li').removeClass();
                    $(this).addClass('hover');
                });

                $('#pills-crowd-tab').click(function () {
                    console.log(user.id);
                    $.get('/friends/crowds',{id:user.id},function (data) {
                        console.log(data);
                        $('.crowdList').renderValues({list:data},{
                            get_data:function (item, value) {
                                $(item).attr('href',"/friend/interface/person/crowdProfiles.html?id=" + value);
                            }
                        })
                    })
                });

                $('.crowdProfiles').click(function () {
					window.location.href = $(this).data('href');
                })
            }
		</script>

		<style>
		 	ul , h3 {padding:0; margin:0;}
		 	li { list-style:none; }
			#list{
				width: 80%;
			}
		 	#list li{}
			#list h3{
				height: 30px;
				line-height: 30px;
				text-indent: 20px;
				background: url("") no-repeat 5px center #66FFFF;
				color: #000000;
			}
			#list .active{
				background: url("") no-repeat 5px center #FF9800;
				color: #000000;
			}
			#list ul{
				display: none;
			}
			#list ul li{
				line-height: 24px;
				border-bottom: 1px solid #333333;
				text-indent: 24px;
			}
			#list ul .hover{
				background: #66FFFF;
			}
			.operation{
				width: 100%;
				display: inline-table;
				position: fixed;
				bottom: 0px;
				max-width: 500px;
				z-index: 9;

			}
			.operation button{
				margin-top: 20px;
				border-radius: initial;
				font-size: 13px;
				padding-top: 7px;
				padding-bottom: 7px;
			}

			.operation button:nth-child(1){
				width: 40%;
			}
			.operation button:nth-child(2){
				background-color: #3E3C3B;
				width: 60%;
				color: white;
			}
		</style>


    </head>
	<body>
	<div class="search-head">
		<div class="row nav-search">
			<div class="col-2">
				<a href="/friend/index.html">
					<span><i class="fa fa-chevron-left fa-2x"></i></span>
				</a>
			</div>
			<div class="col-10">
				<div class="input-group-sm search">
					<input class="form-control searchBtn" placeholder="找攻略">
				</div>
			</div>
		</div>
	</div>

	<ul class="nav nav-pills nav-justified border border-left-0 border-top-0 border-right-0" id="pills-tab" role="tablist">
		<li class="nav-item">
			<a class="nav-link active show" id="pills-dialogue-tab" data-toggle="pill" data-page="dialogue" href="#pills-dialogue">
				<span style="font-weight: bold;">好友</span>
			</a>
		</li>
		<li class="nav-item">
			<a class="nav-link" id="pills-crowd-tab" data-toggle="pill" data-page="crowd" href="#pills-crowd">
				<span style="font-weight: bold;">群</span>
			</a>
		</li>
	</ul>

	<div class="tab-content" id="pills-tabContent">
		<div class="tab-pane fade active show" id="pills-dialogue">
			<div class="container strategyCommend">
				<h6>好友列表</h6>
				<hr>
				<div class="row" id="group">
					<ul id="list" render-loop="list">
						<li class="lis">
							  <h3 render-html="list.name" render-key="list.id" render-fun="set_id"></h3>
								<ul>
									<li>
										<a href="/friend/interface/person/friendProfiles.html?id=">
										<img class="rounded-circle head-img" src="" width="50px">
										<span >1111111111 </span> </a>
									</li>
								</ul>
						</li>
					</ul>
				</div>

			</div>


		</div>
		<div class="tab-pane fade" id="pills-crowd">

			<div class="container crowdList">
				<h6>群列表</h6>
				<hr>
				<div class="chatBox-list" ref="chatBoxlist" render-loop="list">
					<div class="chat-list-people crowdProfiles">
						<a render-fun="get_data" render-key="list.id">
						<div class="chat-name">
							<p render-html="list.name"></p>
						</div>
						<div class="message-num" render-html="list.billboard"></div>
						</a>
						<hr>
					</div>
				</div>
			</div>
		</div>
	</div>
	</body>

	<div class="operation">
		<button class="btn" id="addGroupBtn">增加分组</button>
		<button class="btn" id="addCrowd">新建群</button>
	</div>



	<!--遮罩层-->
	<div id="edit_mask" class="none"></div>

	<!--添加组-->
	<div class="none edit_popup group">
		<div class="title">
			<div class="container info">
				<form id="infoForm" method="post" action="/friends/group" >
					<input type="hidden" name="user.id" class="userId">
					<label>组名</label><input class="form-control" name="name" placeholder="请输入组名">
				</form>
                <button class="btn btn-primary addGroup">确认</button>
			</div>
		</div>
	</div>


	<!--新建群-->
	<div class="none edit_popup crowd">
		<div class="title">
			<div class="container info">
				<form id="crowdForm" method="post" action="/friends/crowds" >
					<input type="hidden" name="user.id" class="userId">
					<label>群名</label><input class="form-control" name="name" placeholder="请输入群名">
					<label>公告</label><input class="form-control" name="billboard" placeholder="请输入群公告">
				</form>
                <button class="btn btn-primary addCrowd">确认</button>
			</div>
		</div>
	</div>
	<script>
		$(function () {
		// 关闭
		function bindEvents() {
			$('#addGroupBtn').on('click', edit);
			$('#addCrowd').on('click', editCrowd);
			$('.btn_close').on('click', close_edit);
			$('.addGroup').on('click',function () {
                $('#infoForm').ajaxSubmit(function (data) {
					if(data.success){
					    window.location.reload();
					}
                })
            });
			$('.addCrowd').on('click',function () {
                $('#crowdForm').ajaxSubmit(function (data) {
                    if(data.success){
                        window.location.reload();
                    }
                })
            })
		}

		bindEvents();

		function edit() {
			var left = ($(document).width() - parseInt($('.edit_popup').css('width'))) / 2;
			$('.group').css('left', left + 'px');
			$('.group').removeClass('none');
			$('#edit_mask').removeClass('none');
		};
		function editCrowd() {
			var left = ($(document).width() - parseInt($('.edit_popup').css('width'))) / 2;
			$('.crowd').css('left', left + 'px');
			$('.crowd').removeClass('none');
			$('#edit_mask').removeClass('none');
		};
		edit();
		editCrowd();

		function close_edit() {
			$('.edit_popup').addClass('none');
			$('#edit_mask').addClass('none');
		};
		close_edit();
		// 点击空白处 关闭  点击变比按钮也可以关闭
		$('#edit_mask').on('click', close_edit);
		});
	</script>
</html>